package chen.web.back.client;

import chen.web.back.client.account.AccountNavigation;
import chen.web.back.client.post.PostNavigation;
import chen.web.back.client.system.SystemConfigNavigation;
import chen.web.back.client.system.SystemInfo;

import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.util.Theme;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.google.gwt.core.client.EntryPoint;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class BackEnd implements EntryPoint, ValueChangeHandler<String> {

	public void onModuleLoad() {
		GXT.setDefaultTheme(Theme.BLUE, true);
		
		if(LoginDialog.checkLogin()){
			Workbench bench = Workbench.getInstance();
			//系统设置
			SystemConfigNavigation scn = new SystemConfigNavigation();
			//帐号管理
			AccountNavigation an = new AccountNavigation();
			//帖子管理
			PostNavigation pn = new PostNavigation();
			bench.addNavigationItem(pn);
			bench.addNavigationItem(an);
			bench.addNavigationItem(scn);
			
			SystemInfo sysInfo = new SystemInfo();
			TabItem tab = Workbench.getInstance().generalTabItem("系统信息", "system-info");
			tab.add(sysInfo);
			Workbench.getInstance().addTabItem(tab);

			History.addValueChangeHandler(this);
			History.fireCurrentHistoryState();
			
			bench.show();
		}
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		// TODO Auto-generated method stub
		if("system-info".equals(event.getValue())){
			SystemInfo sysInfo = new SystemInfo();
			TabItem tab = Workbench.getInstance().generalTabItem("系统信息", "system-info");
			tab.add(sysInfo);
			Workbench.getInstance().addTabItem(tab);
		}
	}
}
